Navigation

More:





Impressum

usage sample

Next: What is HAML-TO-PHP

The interface is kept stupid simple: You feed in HAML strings and you'll get back a string representing PHP code you can eval. Thus you can do whatever you want.

For convenience there is a ready to use interface caching PHP code in files which is used by the sample shipping with the code. It looks like this:

require_once(dirname(__FILE__).'/Haml.php');
define('BASE',dirname(__FILE__));
define('HAML_DIR',BASE.'/haml');
define('HAML_TEMLPATE_CACHE',BASE.'/template-cache');

// create caching haml object
$haml = new HamlFileCache(HAML_DIR, HAML_TEMLPATE_CACHE);

// update cache on each request
// defaults to false
$haml->forceUpdate = true; 
// somewhat more pretty HTML
// defaults to true
$haml->options['ugly'] = false;

// xdebug prevents segfaults (caused by stack overflows)
// by introducing a function call depths.
// default is 100 which is not enough for HAML-TO-PHP
@ini_set('xdebug.max_nesting_level','600');

// the data passed to the .haml file. extract()
// is being used to put keys in scope
$data = array('title' => "OH HAPPY DAY");

// run the template. Parsing, translating to
// PHP and writing 
// cache file is done automatically
// You can replace this implementation
// and store PHP code in sqlite databases
// instead easily
echo $haml->haml('test.haml', $data);

Next: What is HAML-TO-PHP